package com.jsh.mypor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jsh.mypor.pojo.Clazz;
import com.jsh.mypor.pojo.Grade;
import com.jsh.mypor.service.ClazzService;
import com.jsh.mypor.util.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
     private ClazzService clazzService;

    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzsByOpr(   @ApiParam("分页查询的页数") @PathVariable("pageNo") Integer pageNo,
                                    @ApiParam("每页有多少条数据") @PathVariable("pageSize") Integer pageSize,
                                    Clazz clazz
    ){
        //分页 带条件查询
        Page<Clazz> page=new Page<>(pageNo,pageSize);
        //通过服务层
        IPage<Clazz> pageRs=clazzService.getClazzsByOpr(page,clazz);
        //封装Result对象并返回
        return Result.ok(pageRs);
    }
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@RequestBody Clazz clazz){
        boolean b = clazzService.saveOrUpdate(clazz);
        if (!b){
            return Result.fail();
        }
        return Result.ok();

    }
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(
            @RequestBody List<Integer> list){
        boolean b = clazzService.removeByIds(list);
        return Result.ok();
    }
    @GetMapping("/getClazzs")
    public Result getClazzs(){
        List<Clazz> list = clazzService.list();
        return Result.ok(list);

    }
}
